package cn.zhaoguang.usedcar.main.controller;

import cn.zhaoguang.usedcar.common.http.ResultVO;
import cn.zhaoguang.usedcar.common.page.PageRequest;
import cn.zhaoguang.usedcar.main.entity.vo.UserAddVO;
import cn.zhaoguang.usedcar.main.entity.vo.UserUpdateInfoVO;
import cn.zhaoguang.usedcar.main.entity.vo.UserUpdatePasswordVO;
import cn.zhaoguang.usedcar.main.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/7/5 16:07
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户控制器")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @ApiOperation(value = "用户注册", notes = "用户注册")
    public ResultVO register(@RequestBody UserAddVO userAddVO) {
        return userService.add(userAddVO);
    }

    @PutMapping("/updateInfo")
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    public ResultVO update(@RequestBody UserUpdateInfoVO userVO) {
        String result = userService.updateInfo(userVO);
        return ResultVO.success(result);
    }

    @PutMapping("/updatePassword")
    @ApiOperation(value = "修改用户密码", notes = "修改用户密码")
    public ResultVO updatePassword(@RequestBody UserUpdatePasswordVO userVO) {
        String result = userService.updatePassword(userVO);
        return ResultVO.success(result);
    }

    @PostMapping("/listAllUserForManager")
    @ApiOperation(value = "管理员接口-获取所有的用户", notes = "获取所有的用户")
    public ResultVO listAllUserForManager(@RequestBody PageRequest pageRequest) {
        return ResultVO.success("查询成功",userService.listAllUserForManager(pageRequest));
    }
}
